package cn.ziyoufa.smart.smartschool.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.ziyoufa.smart.smartschool.R;
import cn.ziyoufa.smart.smartschool.module.BaseModel;
import cn.ziyoufa.smart.smartschool.module.shutdown.ShutdownValue;


/**
 * Created by apple on 16/7/4.
 */
public class LogListAdapter extends BaseAdapter {
    private List<BaseModel> Bean;
    private Context context;
    private LayoutInflater mLayoutInflater;

    public LogListAdapter(Context context, List<BaseModel> list){
        mLayoutInflater = LayoutInflater.from(context);
        Bean = list;
    }
    @Override
    public int getCount() {
        return Bean.size();
    }

    @Override
    public Object getItem(int position) {
        return Bean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.item_log_list,null);
            holder.shutdown = convertView.findViewById(R.id.shutdown_machine);
            holder.shutup = convertView.findViewById(R.id.shutup_machine);
            holder.created_at   = convertView.findViewById(R.id.created_at);
            holder.shutup_time   = convertView.findViewById(R.id.shutup_time);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        // 取出bean对象
        ShutdownValue bean = (ShutdownValue) Bean.get(position);
        // 设置控件的数据
        holder.shutdown.setText("关机时间："+bean.getEle_shutdown_s_week()+" "+bean.getEle_shutdown_stime());
        holder.shutup.setText("开机时间："+bean.getEle_shutdown_e_week()+" "+bean.getEle_shutdown_etime());
        holder.created_at.setText("写入时间："+bean.getCreated_at());
        holder.shutup_time.setText("单片机写入时间(单位：秒):"+bean.getEle_reduce_time());
        return convertView;
    }
    // ViewHolder用于缓存控件
    class  ViewHolder{
        public TextView shutdown;
        public TextView shutup;
        public TextView created_at;
        public TextView shutup_time;
    }
}
